FUNCTION plotlocation_manip::Init, $
    _REF_EXTRA=_extra

COMPILE_OPT idl2, HIDDEN

; Initialize the manipulator.
IF (~self->IDLitManipulator::Init( $
   NAME='Scatter Plot Point Interegator', $
   TYPES=['IDLPLOT'], $
   _EXTRA = _extra)) THEN $
      RETURN, 0

; Register the cursor of the manipulator.
self->plotlocation_manip::DoRegisterCursor

; Indicate success if all has succeeded.
RETURN, 1
END

; ****************************************************************
; Configure the DoRegisterCursor method
; This method will create the cursor for the manipulator.
pro plotlocation_manip::DoRegisterCursor

  compile_opt idl2, hidden

; Define the default cursor for this manipulation.

  strArray = [ $
        '..              ', $
        '.#.             ', $
        '.##.            ', $
        '.###.           ', $
        '.####.          ', $
        '.#####.         ', $
        '.######.        ', $
        '.#######.       ', $
        '.########.      ', $
        '.#########.     ', $
        '.##########.    ', $
        '......###...    ', $
        '     .###.      ', $
        '      .###.     ', $
        '      .###.     ', $
        '       ....     ']

; Register the new cursor with the tool.
  self->RegisterCursor, strArray, 'LUT', /DEFAULT
END


pro plotlocation_manip::OnMouseDown, oWin, x, y, iButton, $
    KeyMods, nClicks
    self->IDLitManipulator::OnMouseDown, oWin, x, y, iButton, Keymods, nClicks

	if (self.nSelectionList EQ 0) THEN return
	self->Select2DPlots, found=found
	if(found EQ 1) then begin
		self.oplot->WindowToVis, x, y, dataX, dataY
		print, x, y
		print, dataX, dataY
		thresh = 5
		ind = -1
		for i=0L, n_elements((*((*self.uvalue).pseeds))[0,*]) - 1 do begin
			if( ((*((*self.uvalue).pseeds))[0,i] lt dataX + thresh) && ((*((*self.uvalue).pseeds))[0,i] gt dataX - thresh) && ((*((*self.uvalue).pseeds))[1,i] gt dataY - thresh) && ((*((*self.uvalue).pseeds))[1,i] lt dataY + thresh)) then ind = i
		endfor
		if (ind ne -1) $
			then begin
			;plot, (*((*self.uvalue).prays))[*,ind,0]
			;get the windows
			tid = itGetCurrent(tool=otool)
			color=randomu(undef,3)
			for i=0, (*self.uvalue).nrays - 1 do begin
				ovis = otool->getByIdentifier("WINDOW/VIEW_" + strtrim(i + 2,2) + "/VISUALIZATION LAYER")
				ods = ovis->GetCurrentDataSpace()
				oplotn = obj_new('IDLitVisPlot'); have manually set plot data, aweful...
				oplotn._oPlot->SetProperty, datay=(*((*self.uvalue).prays))[*,ind,i], color=color * 256
				ods->add, oplotn
			endfor
		endif
	endif

end

pro plotlocation_manip::Select2DPlots, found=found
	if (self.nSelectionList EQ 0) then return

	self.oplot = (*self.pSelectionList)[0]
	if(obj_isa(self.oplot, 'IDLitVisPlot')) then begin
		found=1
	endif else begin
		found=0
	endelse

end

pro plotlocation_manip__define
	compile_opt idl2, hidden

	void = {plotlocation_manip, $
			inherits IDLitManipulator, $
			oplot: obj_new() }

end